<template>
  <Card style="height:800px">
    <Layout>

        <header>
          <span style="vertical-align:middle">资金源名称:</span>
          <Input v-model="fundName" placeholder="请输入" style="width: 200px" />
          <span style="width: 200px;margin-left: 20px;vertical-align:middle">资金源属性:</span>
          <Select v-model="fundSourceAttribute" style="width:200px">
            <Option v-for="item in fundSourceAttributeList" :value="item.value" :key="item.value">{{ item.label }}</Option>
          </Select>
          <span style="width: 200px;margin-left: 20px;vertical-align:middle">放款方式:</span>
          <Select v-model="fundLoanType" style="width:200px">
            <Option v-for="item in fundLoanTypeList" :value="item.value" :key="item.value">{{ item.label }}</Option>
          </Select>
          <span style="width: 200px;margin-left: 20px;vertical-align:middle">状态:</span>
          <Select v-model="status" style="width:200px">
            <Option v-for="item in statusList" :value="item.value" :key="item.value">{{ item.label }}</Option>
          </Select>
          <Button type="primary" @click="initPage" style="margin-left: 20px;" >查询</Button>
          <Button type="primary" @click="addFund" style="margin-left: 20px;" >新增</Button>
        </header>
        <Table border :columns="tableColumns" :data="tableDatas" style="margin-top:20px;"></Table>
        <div style="text-align:center;width:50%;margin:36px auto;">
          <Page :total="totalPage" :current="currentPage" :page-size="pageSize" show-elevator show-total @on-change="handlePageChange"></Page>
        </div>
    </Layout>
  </Card>
</template>

<script>
export default {
  data () {
    return {
      test: 'hello',
      isEdit: false,
      status: '',
      fundName: '',
      statusList: [
        {
          value: '',
          label: '请选择'
        },
        {
          value: '0',
          label: '正常'
        },
        {
          value: '1',
          label: '失效'
        }
      ],
      fundSourceAttribute: '',
      fundSourceAttributeList: [
        {
          value: '',
          label: '请选择'
        },
        {
          value: 'A0',
          label: 'P2P'
        },
        {
          value: 'A1',
          label: '小贷公司'
        }
      ],
      fundLoanType: '',
      fundLoanTypeList: [
        {
          value: '',
          label: '请选择'
        },
        {
          value: 'A',
          label: '自动'
        },
        {
          value: 'P',
          label: '人工'
        }
      ],
      tableColumns: [
        {
          type: 'index',
          title: '序号',
          align: 'center'
        },
        {
          title: '资金源名称',
          key: 'fundName',
          align: 'center'
        },
        {
          title: '资金源属性',
          key: 'fundSourceAttributeName',
          align: 'center'
        },
        {
          title: '法人手机号码',
          key: 'fundSourceMobile',
          align: 'center'
        },
        {
          title: '放款方式',
          key: 'fundLoanType',
          align: 'center'
        },
        {
          title: '状态',
          key: 'status',
          align: 'center'
        },
        {
          title: '操作',
          align: 'center',
          render: (h, param, index) => {
            var vm = this
            return h('div', [
              h(
                'Button',
                {
                  props: {
                    type: 'primary',
                    size: 'small'
                  },
                  style: {
                    marginRight: '5px'
                  },
                  on: {
                    click: () => {
                      var fundP = JSON.stringify(param.row)
                      vm.$router.push({
                        name: 'fundseeiview',
                        query: { fundParam: fundP, type: '1' }
                      })
                    }
                  }
                },
                '查看'
              ),
              h(
                'Button',
                {
                  props: {
                    type: 'info',
                    size: 'small'
                  },
                  style: {
                    marginRight: '5px'
                  },
                  on: {
                    click: () => {
                      var fundP = JSON.stringify(param.row)
                      vm.$router.push({
                        name: 'fundseeiview',
                        query: { fundParam: fundP, type: '2' }
                      })
                    }
                  }
                },
                '编辑'
              ),
              h(
                'Button',
                {
                  props: {
                    type: 'error',
                    size: 'small'
                  },
                  style: {
                    marginRight: '5px'
                  },
                  on: {
                    click: () => {
                      var fundP = {
                        fundCode: param.row.fundCode,
                        deleteFlag: '1',
                        judge: 'delete'
                      }
                      this.$ajax.post(this.$appContext.marvels_core_financial + 'financial/fund/service/addFundSource', fundP)
                        .then(re => {
                          this.$Message.warning(re.data.data)
                          if (re.data.code === 'success') {
                            this.initPage()
                          }
                        })
                        .catch(er => { })
                    }
                  }
                },
                '删除'
              )
            ])
          }
        }
      ],
      tableDatas: [],
      totalPage: 0,
      currentPage: 1,
      pageSize: 20
    }
  },
  methods: {
    addFund () {
      this.$router.push({ name: 'fundseeiview', query: { type: '3' } })
    },
    handleRouterGo (toPage, actKey) {
      // console.log(actKey)
      if (actKey != null) {
        this.$router.push({ name: toPage, params: { actKey: actKey } })
      } else {
        this.$Message.warning('参数为空')
      }
    },
    handlePageChange (goPage) {
      // console.log(goPage)
      // this.$router.push({path:'/flow_def',query:{pageNo:goPage}});
      // 设置查询参数
      // this.$router.push({name:'flow_def',query:{pageNo:new Date().getTime()},params:{pageNo:goPage}});//类似post传参
      this.initPage(goPage)
    },
    addFlowPage () {
      this.$router.push({ name: 'flow_def_add', params: {} }) // 类似post传参
    },
    initPage (goPage) {
      if (parseFloat(goPage).toString() === 'NaN') {
        goPage = 1
      }
      var vm = this
      var params = {
        pageNum: goPage,
        pageSize: vm.pageSize,
        fundName: vm.fundName,
        fundSourceAttribute: vm.fundSourceAttribute,
        fundLoanType: vm.fundLoanType,
        status: vm.status
      }
      this.$ajax.post(this.$appContext.marvels_core_financial + 'financial/fund/service/list', params)
        .then(re => {
          this.totalPage = re.data.data.total
          this.currentPage = re.data.pageNum
          this.tableDatas = []
          var datas = re.data.data.list || []
          datas.forEach(item => {
            var tData = {}
            if (item.status === '0') {
              tData.status = '正常'
            } else {
              tData.status = '失效'
            }

            tData.fundSourceAttributeName = item.fundSourceAttributeName
            tData.fundSourceAttribute = item.fundSourceAttribute
            tData.fundName = item.fundName
            tData.fundSourceMobile = item.fundSourceMobile
            tData.fundSourceIcNo = item.fundSourceIcNo
            tData.fundCode = item.fundCode
            if (item.fundLoanType === 'A') {
              tData.fundLoanType = '自动'
            } else if (item.fundLoanType === 'P') {
              tData.fundLoanType = '人工'
            }
            this.tableDatas.push(tData)
          })
        })
        .catch(er => {

        })
    }
  },
  created: function () {
    this.$ajax = this.$util.ajax(this.$appContext.marvels_core_financial)
    this.initPage()
  }
}
</script>

<style lang="less">
</style>
